package com.example.homework9.service;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.homework9.R;

public class startService extends Fragment {
    public startService() {
        super(R.layout.startservice);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        // 播放
        Button playMusicButton = getView().findViewById(R.id.playMusic2Button);
        playMusicButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MusicService.class);
                getActivity().startService(intent);
            }
        });

        // 停止
        Button stopMusicButton = getView().findViewById(R.id.pauseMusic2Button);
        stopMusicButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(),MusicService.class);
                getActivity().stopService(intent);
            }
        });
    }
}
